<?php
session_start() ;
if(!isset($_SESSION["login"]) || $_SESSION["login"] == "")
{   
  header("Location: index.php?error=4") ;
}
require("fonctions.php");
$code=$_GET["error"];
$action = $_GET["action"];
if($lang=="FR"){
    $lang="FR";
    include("lang/fr_lang.php");
}elseif($lang=="EN"){
    $lang="EN";
    include("lang/en_lang.php");
}else{
    $lang="FR";
    include("lang/fr_lang.php");
}

?>

<html>
<head>
<title><?php echo TXT_TITLE;?></title>
 <link rel="stylesheet" type="text/css" href="style.css" >  
<script type="text/javascript">
//<![CDATA[

function valider() {
  // si la valeur du champ prenom est non vide
  if((document.form1.nom.value != "") && (document.form1.prenom.value != "") && (document.form1.email.value != "") && (document.form1.profil.value != "") && (document.form1.instit.value != "")) {
    // alors on envoie le formulaire
    document.form1.submit();
    return true;
  }
  else {
    // sinon on affiche un message
    alert("Remplir les champs obligatoires avant d'enregistrer svp !");
    return false;
  }

}
</script>
</head>

<body>
<?php require("menu.php");
?>
<br>
<?php echo error_message($code);?>
<div class="texte_acc">
     <fieldset>
    <legend><p class="titre_1"><u><?php echo TXT_LIST_USERS;?> </u></p></legend>
    
    

<a href="ad_users.php?cur=2&action=add_user" class="bouton"><?php echo TXT_USER_ADD;?></a>
<br>
<?php
if($action=="add_user"){
    ?>
<form action="controler.php?action=add_user" method="post" name="form1">
    <fieldset>
        <legend><?php echo TXT_USER_ADD;?></legend>
        
    
<TABLE class="">
    <tr>
        <td><?php echo TXT_NOM;?>*</td><td><input type="text" name="nom" size="45"></td>
    </tr>
     <tr>
        <td><?php echo TXT_PRENOM;?>*</td><td><input type="text" name="prenom" size="45"></td>
    </tr> 
     <tr>
        <td><?php echo TXT_LOGIN;?>*</td><td><input type="text" name="login" size="45"></td>
    </tr> 
     <tr>
        <td><?php echo TXT_MOTDEPASSE;?></td><td><input type="password" name="password" size="45"></td>
    </tr> 
    
    <tr>
        <td><?php echo TXT_INSTITUTION;?>*</td><td><input type="text" name="instit" size="45"></td>
    </tr> <tr>
        <td><?php echo TXT_PROFIL;?>*</td><td><select name="profil">
                <option>--</option>
                 <option value="USER">USER</option>
                  <option value="ADMIN">ADMIN</option>
                  
            </select></td>
    </tr> 
    
     <tr>
            <td><?php echo TXT_FONCTION;?></td> <td>
                <select name="fonction">
                    
                <option>--</option>
                <?php 
                $sql="select * from type_grp_professions order by descr";
                    $res = mysql_query($sql);
                    while($r = mysql_fetch_object($res)){
                    ?>
        <optgroup label="<?php echo "$r->descr";?>">
                <?php 
                    echo $sql1="select * from type_professions where type=$r->id order by id";
                    $res1 = mysql_query($sql1);
                    while($r1 = mysql_fetch_object($res1)){
                ?>
                 <option value="<?php echo $r1->id;?>"><?php echo $r1->descr;?></option>
               <?php }?>
            </optgroup>
  <?php }?>      
            </select></td>
            <td><?php echo TXT_AUTRES;?></td> <td><input type="text" name="autres_fonctions"></td>
         </tr>
    
    <tr>
        <td><?php echo TXT_EMAIL;?></td><td><input type="text" name="email" size="45"></td>
    </tr>
     <tr>
        <td><?php echo TXT_TELEPHONE;?></td><td><input type="text" name="tel" size="45"></td>
    </tr>
    <tr>
        <td colspan="2" align="center"><input type="submit" value="<?php echo TXT_SUBMIT;?>" onclick="return valider();"></td>
    </tr>
    
</table>
        </fieldset>
    </form>
<?php
}
?>




   <TABLE class="tab_lis_op3">
<TR>
	<TH class="tab_dis_head"><?php echo TXT_ID;?></TH>
	<TH class="tab_dis_head"><?php echo TXT_NOM;?></TH>
	<TH class="tab_dis_head"><?php echo TXT_PRENOM;?></TH>
        <TH class="tab_dis_head"><?php echo TXT_TELEPHONE;?></TH>
        <TH class="tab_dis_head"><?php echo TXT_EMAIL;?></TH>
	<TH class="tab_dis_head"><?php echo TXT_ORGANISATION;?></TH>
        <TH class="tab_dis_head"><?php echo TXT_PROFIL;?></TH>
	<TH class="tab_dis_head"><?php echo TXT_ACTION;?></TH>
</TR>

<?php
$sql="select * from users";
$res = mysql_query($sql);
while($r = mysql_fetch_object($res)){
?>
<TR>
	<TD class="tab_dis_data"><?php echo $r->id;?></TD>
	<TD class="tab_dis_data"><?php echo $r->nom;?></TD>
	<TD class="tab_dis_data"><?php echo $r->prenom;?></TD>
        <TD class="tab_dis_data"><?php echo $r->tel;?></TD>
        <TD class="tab_dis_data"><?php echo $r->email;?></TD>
	<TD class="tab_dis_data"><?php echo $r->instit;?></TD>
	<TD class="tab_dis_data"><?php echo $r->profil;?></TD>
        <TD class="tab_dis_data"><a href="controler.php?action=status&id=<?php echo $r->id;?>"><?php if(getUserStatut($r->id)=="ON"){echo TXT_DESACTIVER;}else{ echo TXT_ACTIVER;}?></a> /
            <a href="ad_mod_users.php?action=mod_user&cur=2&id=<?php echo $r->id;?>"> <?php echo TXT_MOD;?></a> / 
            <a href="controler.php?action=sup_user&id=<?php echo $r->id;?>" onClick="return confirm('<?php echo TXT_MSG_SUP_USER;?>')"><?php echo TXT_SUP;?></a></TD>
</TR>


<?php }?>
</TABLE>
    
     </fieldset>
    
</div>

<?php
require_once ("footer.php");
?>
